﻿using Microsoft.Xna.Framework;
using GameLibrary;
using Rescue_of_the_Dwarvenzombies.SceneObjects.SceneObjectsHandlers;

namespace Rescue_of_the_Dwarvenzombies.SceneObjects.GameObjects.Items.ConsumableItems
{
    internal class Potion : ConsumableItem, IStatic
    {
        private float _restorePower;
        private ItemHandler _itemHandler;

        /// <summary>
        /// Initializes a new instance of the Potion class.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="itemHandler">The item handler.</param>
        public Potion(Vector2 position, ItemHandler itemHandler)
        {
            _duration = Constant.POTION_DURATION;
            _restorePower = Constant.POTION_RESTORE_POWER;
            _itemHandler = itemHandler;
            TextureName = Constant.POTION_TEXTURE_NAME;
            RectangleWidth = Constant.POTION_RECTANGLE_WIDTH;
            RectangleHeight = Constant.POTION_RECTANGLE_HEIGHT;
            TintColor = Color.White;
            Position = position;
            SourceRectangle = new Rectangle(0, 0, RectangleWidth, RectangleHeight);
            BoundingBox = new BoundingBox(new Vector3(position.X, position.Y, 0), new Vector3(position.X + RectangleWidth, position.Y + RectangleHeight, 0));
        }

        /// <summary>
        /// Removes the item if the duration has passed.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public override void Update(GameTime gameTime)
        {
            _duration -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (_duration <= 0)
                _itemHandler.RemoveItem(this);
        }
    }
}